1 package jrre.gui;
2
3 import jrre.JRRE;
4 import java.awt.*;
5 import javax.swing.*;
6 import javax.swing.tree.*;
7 import java.awt.event.*;
8
9 public class MethodAreaGui extends JFrame {
10
11 private JTree methodAreaTree = new JTree();
12 private DefaultMutableTreeNode treeRoot;
13 private DefaultMutableTreeNode lastAdded;
14 private DefaultTreeModel treeModel;
15 int classCount = 0;
16
17 public MethodAreaGui(){
18
19 super("Java Method Area");
20
21 // Set up and add tree.
22 treeRoot = new DefaultMutableTreeNode("Java Method Area - Loading classes...");
23 treeModel = new DefaultTreeModel(treeRoot);
24
25 methodAreaTree = new JTree(treeModel);
26
27 MouseListener mouseListener = new MouseAdapter(){
28 public void mousePressed(MouseEvent event){
29
30 int x = event.getX();
31 int y = event.getY();
32 int button = event.getButton();
33
34 int row = methodAreaTree.getRowForLocation(x, y);
35 TreePath path = methodAreaTree.getPathForLocation(x, y);
36
37 if(row != -1){
38 if(event.getClickCount() == 1)
39 SingleClick(row, path, x, y, button);
40 else if(event.getClickCount() == 2)
41 DoubleClick(row, path, x, y, button);
42 }
43
44 }
45 };
46
47 methodAreaTree.addMouseListener(mouseListener);
48
49 JPanel treePanel = new JPanel();
50 treePanel.add(methodAreaTree);
51
52 JScrollPane scrollPane = new JScrollPane(methodAreaTree);
53 //scrollPane.add(methodAreaTree);
54 Container content = getContentPane();
55 content.add(scrollPane);
56
57 addWindowListener(new WindowDestroyer());
58
59 setSize(300,400);
60 setLocation(400, 300);
61 if(JRRE.guiOn())
62 setVisible(true);
63 }
64
65 public void clear(){
66
67 classCount = 0;
68 treeRoot.removeAllChildren();
69 }
70
71 public void addClass(jrre.api.java.lang.Class className){
72
73 treeRoot.setUserObject("Java Method Area: "+(classCount++));
74 DefaultMutableTreeNode classToAdd = new DefaultMutableTreeNode(className);
75 treeRoot.add(classToAdd);
76
77 lastAdded = classToAdd;
78
79 }
80
81 public void removeClass(String className){
82
83 }
84
85 public void refresh(){
86
87 treeModel.reload();
88
89 TreePath path = new TreePath(lastAdded.getPath());
90 methodAreaTree.expandPath(path);
91 }
92
93 private void SingleClick(int row, TreePath path, int x, int y, int button){
94 }
95
96 private void DoubleClick(int row, TreePath path, int x, int y, int button){
97
98 DefaultMutableTreeNode selected = (DefaultMutableTreeNode)path.getLastPathComponent();
99
100 jrre.api.java.lang.Class selectedClass = (jrre.api.java.lang.Class)selected.getUserObject();
101
102 TextEditor editor = new TextEditor();
103 editor.setText(selectedClass.getString());
104 //editor.setText(selectedClass.getFullyQualifiedName());
105 editor.setVisible(true);
106 /*
107 if(button == 3){
108
109 if(selected instanceof JavaQuizNode)
110 quizPopup.show(tree, x,y);
111 else if(selected instanceof InstructionsNode)
112 instructionsPopup.show(tree, x,y);
113 else if(selected instanceof JavaTestCaseNode)
114 testCasePopup.show(tree, x,y);
115 else
116 instructionsPopup.show(tree, x,y);
117 }
118 */
119 }
120
121 class WindowDestroyer extends WindowAdapter{
122 public void windowClosing(WindowEvent e){
123 System.exit(0);
124 }
125 }
126
127 }
128
This page was automatically generated by Maven